<template>
    <div>
        <van-nav-bar title="商品分类" left-text="返回" left-arrow @click-left="onClickLeft" />
        <div v-for="item in categories">
            <van-row>
                <van-col span="6">
                    <van-sidebar v-model="active">
                        <router-link :to="{name:'search',params:{query:item.cat_name}}">
                            <van-sidebar-item :title="item.cat_name" />

                        </router-link>
                       
                        
                    </van-sidebar>
                </van-col>

                <van-col span="18">
                       
                    <div v-for="item in categories[active]?.children">
                    <h4>{{ item.cat_name }}</h4>
                        <van-grid :column-num="4">
                            <van-grid-item v-for="items in item.children"  :icon="items.cat_icon" :text="items.cat_name" />
                        </van-grid>
                    </div>

                </van-col>
            </van-row>

        </div>


    </div>
</template>

<script setup>
import { ref } from 'vue';
import { categoriesApi } from '@/api/api';
import router from '@/router';
let categories = ref([])
categoriesApi().then(res => {
    console.log('分类数据', res)
    categories.value = res.data.message
    router.push('/search')
})
let active = ref(1)

</script>

<style lang="scss" scoped></style>